<?php
	include "common.php";
	session_start();
	error_reporting(0);
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userLink = $_SESSION['userLink'];
	if($userLink!="employee.php"){
		echo "Sorry, You have no right to visit this page!!";
		exit;
	}
	$eid = $_SESSION['id'];
	$userFname = $_SESSION['userFname'];
	$userLname = $_SESSION['userLname'];
	$role = $_SESSION['role'];
	
	$userSql = "SELECT * FROM user WHERE e_id = '$eid'";
	$userSqlQuery = mysql_query($userSql);
	$userSqlResult = mysql_fetch_assoc($userSqlQuery);
	
	$email = $userSqlResult['email'];
	$notification = $userSqlResult['notification'];
	$OrganogramSql = "SELECT * FROM company_organogram WHERE e_id = '$eid'";
	$OrganogramSqlQuery = mysql_query($OrganogramSql);
	$OrganogramSqlQueryResult = mysql_fetch_assoc($OrganogramSqlQuery);
	
	$deptName = $OrganogramSqlQueryResult['dept'];
	$designation = $OrganogramSqlQueryResult['e_designation'];
	
	$sql = "SELECT * FROM user WHERE e_id = '$eid'";
	$sqlQuery = mysql_query($sql);
	$sqlQueryResult = mysql_fetch_assoc($sqlQuery);
	
	$email = $sqlQueryResult['email'];
	$monthForAttendance = $_GET['cmonth'];
	$monthForLateAttendance = $_GET['cmonthForLateAttendance'];
	$monthForLateAbsent = $_GET['cmonthForAbsent'];
	$timezone_offset = 6; // for getting local time offset hrs
	$systemDate = gmdate('y-m-d', time()+$timezone_offset*60*60);
	if($monthForAttendance == ''){
		$monthForAttendance = gmdate('m', time()+$timezone_offset*60*60);
	}
	if($monthForLateAttendance == ''){
		$monthForLateAttendance = gmdate('m', time()+$timezone_offset*60*60);
	}
	if($monthForLateAbsent == ''){
		$monthForLateAbsent = gmdate('m', time()+$timezone_offset*60*60);
	}
	$searchingDate = $_POST['date'];
	$searchingMonth = $_POST['month'];
	$searchingYear = $_POST['year'];
	$searchingDate1 = $_POST['date1'];
	$searchingMonth1 = $_POST['month1'];
	$searchingYear1 = $_POST['year1'];
	$year = gmdate('y', time()+$timezone_offset*60*60);
	$day = gmdate('d', time()+$timezone_offset*60*60);
	$current_month = gmdate('m', time()+$timezone_offset*60*60);
	$compToday = strtotime($systemDate);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="emp_index.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="show_report.css" />
<link rel="icon" type="image/ico" href="images/favicon.ico"></link> 
<link rel="shortcut icon" href="images/favicon.ico"></link>
<script src="curvycorners.src.js" type="text/javascript"></script>
<script src="login.js" type="text/javascript"></script>
<script src="employee.js" type="text/javascript"></script>
<title><?php echo "Welcome to ".$userFname." ".$userLname; ?></title>
</head>

<body>
<div class="main_div_other">
	<p><img src="images/creato_logo.jpg" /></p>
    <p id="creatobd">www.creatobd.com</p>
    <p id="date"><script>document.write(new_month+" "+new_date+", "+old_date.getFullYear()+" || "+new_day);</script></p>
    <div class="other_page_icons">
    	<div class="new_notification">
        	<img src="images/arrow_up.JPG" /><?php if ($notification >0){?><p>You have<?php echo " ".$notification." ";?>new notification</p><?php }?>
        </div><!--end of new_notification-->
    	<ul>
        	<a href="employee.php"><li><div id="home"></div><p>home</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="work_night.php"><li><div id="employee"></div><p>Apply for</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="emp_attendance.php"><li><div id="attendance"></div><p>attendance</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="emp_leave.php"><li><div id="leave"></div><p>leave</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="notification.php"><li><div id="notification"></div><p>notification</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="emp_black_box.php"><li><div id="blackbox"></div><p>black box</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="index.php"><li><div id="logout"></div><p>log out</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
        </ul>
    </div><!-- end of other_page_icons-->
    
</div><!-- end of main_div_other-->
<div class="othrpage_1">
    <p>My Attendance Report</p>
</div><!-- end of othrpage_1-->
<div class="human_portal">
  		<p>creato human resourse portal</p>
</div><!-- end of human_portal-->
<div class="page_content">
    	<p class="header_page_content">Monthly Attendance</p>
        <table cellpadding="0" cellspacing="0">
        	<tr class="table_header_1"  valign="top" width="300px;">
            	<?php 
					$lmonth=$monthForAttendance-1;
					if($lmonth<1){
						$lmonth=1;
					}
				?>
            	<a href="show_report.php?cmonth=<?php echo $lmonth; ?>"><div class="left_table_arrow"></div></a>
                <?php 
					$nextMonth = $monthForAttendance+1; 
					if($nextMonth>$current_month){
						$nextMonth=$current_month;
					}
				?>
                <a href="show_report.php?cmonth=<?php echo $nextMonth; ?>"><div class="right_table_arrow"></div></a>
            	<td colspan="5">
                	<p>
						<?php							
							$timestamp = mktime(0, 0, 0, $monthForAttendance,1);
							echo date("M", $timestamp); 
						?>
                    </p>
                </td>
            </tr>
            <?php
            $collectId = "SELECT * FROM attendance WHERE e_id = '$eid' and date between '$year-$monthForAttendance-01'and '$year-$monthForAttendance-31'";
				$collectIdQuery = mysql_query($collectId);
				$ifEmployeeHasAnyAttendance = mysql_num_rows($collectIdQuery);
				if($ifEmployeeHasAnyAttendance>0){
				?>
                    <tr valign="top" class="table_header_2">
                        <td width="60px"><p>Date</p></td>
                        <td width="60px;"><p>Day</p></td>
                        <td width="60px;"><p>In Time</p></td>
                        <td width="60px;"><p>Out Time</p></td>
                        <td width="60px;"><p>Status</p></td>
                    </tr>
            <?php
				}
				else{
					?>
					<tr valign="top" class="table_header_2">
                        <td width="300px"><p style="color:#F00">You have no attendance of this month</p></td>                        
                    </tr>
                    <?php
				}
				while($collectIdFetchArray = mysql_fetch_array($collectIdQuery)){
					$collectDate = $collectIdFetchArray['date'];
					$collectDay = $collectIdFetchArray['day'];
					$collectInTime = $collectIdFetchArray['in_time'];
					$collectSatus = $collectIdFetchArray['status'];
					$collectOutTime = $collectIdFetchArray['out_time'];
			?>
            <tr valign="top" class="table_header_3">
            	<td width="60px"><p><?php echo $collectDate; ?></p></td>
                <td width="60px;"><p><?php echo $collectDay; ?></p></td>
                <td width="60px;"><p><?php echo date('h:i A',strtotime($collectInTime)); ?></p></td>
                <td width="60px;"><p><?php echo date('h:i A',strtotime($collectOutTime)); ?></p></td>
                <td width="60px;">         
                <?php
                	if($collectSatus==0){
				?>
                		<p style="color:#F00">Late</p>
                <?php
                	}
					else if($collectSatus==2){
						?>
                        <p style="color:#C90">Absent</p>
                        <?php
					}
					else{						
				?>
                		<p style="color:#060">In Time</p>                          
                <?php
					}
				?>
                </td>
            </tr>
            <?php } ?>
        </table>
        
        <p class="header_page_content">Monthly Late Attendance</p>
        <table cellpadding="0" cellspacing="0">
        	<tr class="table_header_1"  valign="top" width="300px;">
            	<?php 
					$lastMonthForLattd = $monthForLateAttendance-1;
					if($lastMonthForLattd<1){
						$lastMonthForLattd=1;
					} 
				?>
            	<a href="show_report.php?cmonthForLateAttendance=<?php echo $lastMonthForLattd; ?>"><div class="left_table_arrow"></div></a>
				<?php 
					$nextMonthForLattd = $monthForLateAttendance+1; 
					if($nextMonthForLattd>$current_month){
						$nextMonthForLattd=$current_month;
					}
				?>
                <a href="show_report.php?cmonthForLateAttendance=<?php echo $nextMonthForLattd; ?>"><div class="right_table_arrow"></div></a>
            	<td colspan="5">
                	<p>
                    	<?php							
							$timestamp = mktime(0, 0, 0, $monthForLateAttendance,1);
							echo date("M", $timestamp); 
						?>
                    </p>
                </td>
            </tr>
            <?php
            $collectId = "SELECT * FROM attendance WHERE e_id = '$eid' and status='0' and date between '$year-$monthForLateAttendance-01'and '$year-$monthForLateAttendance-31'";
				$collectIdQuery = mysql_query($collectId);
				$ifEmployeeHasAnyLate = mysql_num_rows($collectIdQuery);
				if($ifEmployeeHasAnyLate>0){
				?>
                    <tr valign="top" class="table_header_2">
                        <td width="60px"><p>Date</p></td>
                        <td width="60px;"><p>Day</p></td>
                        <td width="60px;"><p>In Time</p></td>
                        <td width="60px;"><p>Out Time</p></td>
                        <td width="60px;"><p>Status</p></td>
                    </tr>
             <?php
				}
				else{
					?>
					<tr valign="top" class="table_header_2">
                        <td width="300px"><p style="color:#060">You have no late attendance of this month</p></td>                        
                    </tr>
              <?php
				}
				$countTotalLateAttendance = 0;
				while($collectIdFetchArray = mysql_fetch_array($collectIdQuery)){
					$collectDate = $collectIdFetchArray['date'];
					$collectDay = $collectIdFetchArray['day'];
					$collectInTime = $collectIdFetchArray['in_time'];
					$collectSatus = $collectIdFetchArray['status'];
					$collectOutTime = $collectIdFetchArray['out_time'];
			?>
            <tr valign="top" class="table_header_3">
            	<td width="60px"><p><?php echo $collectDate; ?></p></td>
                <td width="60px;"><p><?php echo $collectDay; ?></p></td>
                <td width="60px;"><p><?php echo date('h:i A',strtotime($collectInTime)); ?></p></td>
                <td width="60px;"><p><?php echo date('h:i A',strtotime($collectOutTime)); ?></p></td>                
                <td width="60px;"><p style="color:#F00">Late</p></td>
            </tr>
            <?php				
			 }
			 if($ifEmployeeHasAnyLate>0){
				 ?>
                 <tr valign="top" class="table_header_3">
                        <td colspan="5"><p style="color:#F00">Total late of this month: <b><?php echo $ifEmployeeHasAnyLate; ?></b></p></td>              
                 </tr>
                 <?php
			 }
			?>           
        </table>
        <p class="header_page_content">Monthly Absent</p>
        <table cellpadding="0" cellspacing="0">
        	<tr class="table_header_1"  valign="top" width="300px;">
            	<?php 
					$lastMonthForAbsent = $monthForLateAbsent-1;
					if($lastMonthForAbsent<1){
						$lastMonthForLattd=1;
					} 
				?>
            	<a href="show_report.php?cmonthForAbsent=<?php echo $lastMonthForAbsent; ?>"><div class="left_table_arrow"></div></a>
				<?php 
					$nextMonthForAbsent = $monthForLateAbsent+1; 
					if($nextMonthForAbsent>$current_month){
						$nextMonthForAbsent=$current_month;
					}
				?>
                <a href="show_report.php?cmonthForAbsent=<?php echo $nextMonthForAbsent; ?>"><div class="right_table_arrow"></div></a>
            	<td colspan="5">
                	<p>
                    	<?php							
							$timestamp = mktime(0, 0, 0, $monthForLateAbsent,1);
							echo date("M", $timestamp); 
						?>
                    </p>
                </td>
            </tr>
            <?php
            $collectId = "SELECT * FROM attendance WHERE e_id = '$eid' and status='2' and date between '$year-$monthForLateAbsent-01'and '$year-$monthForLateAbsent-31'";
				$collectIdQuery = mysql_query($collectId);
				$ifEmployeeHasAnyLate = mysql_num_rows($collectIdQuery);
				if($ifEmployeeHasAnyLate>0){
				?>
                    <tr valign="top" class="table_header_2">
                        <td width="60px"><p>Date</p></td>
                        <td width="60px;"><p>Day</p></td>
                        <td width="60px;"><p>In Time</p></td>
                        <td width="60px;"><p>Out Time</p></td>
                        <td width="60px;"><p>Status</p></td>
                    </tr>
             <?php
				}
				else{
					?>
					<tr valign="top" class="table_header_2">
                        <td width="300px"><p style="color:#060">You have no absent of this month</p></td>                        
                    </tr>
              <?php
				}
				$countTotalLateAttendance = 0;
				while($collectIdFetchArray = mysql_fetch_array($collectIdQuery)){
					$collectDate = $collectIdFetchArray['date'];
					$collectDay = $collectIdFetchArray['day'];
					$collectInTime = $collectIdFetchArray['in_time'];
					$collectSatus = $collectIdFetchArray['status'];
			?>
            <tr valign="top" class="table_header_3">
            	<td width="60px"><p><?php echo $collectDate; ?></p></td>
                <td width="60px;"><p><?php echo $collectDay; ?></p></td>
                <td width="60px;"><p><?php echo $collectInTime; ?></p></td>
                <td width="60px;"><p>#####</p></td>
                <td width="60px;"><p style="color:#C90">Absent</p></td>
            </tr>
            <?php				
			 }
			 if($ifEmployeeHasAnyLate>0){
				 ?>
                 <tr valign="top" class="table_header_3">
                        <td colspan="5"><p style="color:#F00">Total absent of this month: <b><?php echo $ifEmployeeHasAnyLate; ?></b></p></td>              
                 </tr>
                 <?php
			 }
			?>           
        </table>
        
        <p class="header_page_content">Search For Attendance Report</p>
        <form action="show_report.php" method="post">
        <div class="search_option">
        	<div class="search_option_1">            
        	<p><b>From</b> Date</p>            
            <select name="date">
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
                  <option value="5">5</option>
                  <option value="6">6</option>
                  <option value="7">7</option>
				  <option value="8">8</option>
                  <option value="9">9</option>
                  <option value="10">10</option>
                  <option value="11">11</option>
                  <option value="12">12</option>
                  <option value="13">13</option>
                  <option value="14">14</option>
				  <option value="15">15</option>
                  <option value="16">16</option>
                  <option value="17">17</option>
                  <option value="18">18</option>
                  <option value="19">19</option>
                  <option value="20">20</option>
                  <option value="21">21</option>
				  <option value="22">22</option>
                  <option value="23">23</option>
                  <option value="24">24</option>
                  <option value="25">25</option>
                  <option value="26">26</option>
                  <option value="27">27</option>
                  <option value="28">28</option>
				  <option value="29">29</option>
				  <option value="30">30</option>
				  <option value="30">30</option>
	              <option value="31">31</option>						           
            </select>
            </div><!-- search_option_1 -->
            <div class="search_option_1">
        	<p>Month</p>
            <select name="month">
                  <option value="1">Jan</option>
                  <option value="2">Feb</option>
                  <option value="3">Mar</option>
                  <option value="4">Apr</option>
                  <option value="5">May</option>
                  <option value="6">Jun</option>
                  <option value="7">Jul</option>
                  <option value="8">Aug</option>
                  <option value="9">Sep</option>
                  <option value="10">Oct</option>
                  <option value="11">Nov</option>
                  <option value="12">Dec</option>
            </select>
            </div><!-- search_option_1 -->
            <div class="search_option_1">
        	<p>Year</p>
            <select name="year">
                  <option value="2011">2011</option>
                  <option value="2012">2012</option>
                  <option value="2013">2013</option>
                  <option value="2014">2014</option>
                  <option value="2015">2015</option>
                  <option value="2016">2016</option>
                  <option value="2017">2017</option>
            </select>
            
			
            </div><!-- search_option_1 -->
            <div class="search_option_1">            
        	<p><b>To</b> Date</p>            
            <select name="date1">
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
                  <option value="5">5</option>
                  <option value="6">6</option>
                  <option value="7">7</option>
				  <option value="8">8</option>
                  <option value="9">9</option>
                  <option value="10">10</option>
                  <option value="11">11</option>
                  <option value="12">12</option>
                  <option value="13">13</option>
                  <option value="14">14</option>
				  <option value="15">15</option>
                  <option value="16">16</option>
                  <option value="17">17</option>
                  <option value="18">18</option>
                  <option value="19">19</option>
                  <option value="20">20</option>
                  <option value="21">21</option>
				  <option value="22">22</option>
                  <option value="23">23</option>
                  <option value="24">24</option>
                  <option value="25">25</option>
                  <option value="26">26</option>
                  <option value="27">27</option>
                  <option value="28">28</option>
				  <option value="29">29</option>
				  <option value="30">30</option>
				  <option value="30">30</option>
	              <option value="31">31</option>						           
            </select>
            </div><!-- search_option_1 -->
            <div class="search_option_1">
        	<p>Month</p>
            <select name="month1">
                  <option value="1">Jan</option>
                  <option value="2">Feb</option>
                  <option value="3">Mar</option>
                  <option value="4">Apr</option>
                  <option value="5">May</option>
                  <option value="6">Jun</option>
                  <option value="7">Jul</option>
                  <option value="8">Aug</option>
                  <option value="9">Sep</option>
                  <option value="10">Oct</option>
                  <option value="11">Nov</option>
                  <option value="12">Dec</option>
            </select>
            </div><!-- search_option_1 -->
            <div class="search_option_1">
        	<p>Year</p>
            <select name="year1">
                  <option value="2011">2011</option>
                  <option value="2012">2012</option>
                  <option value="2013">2013</option>
                  <option value="2014">2014</option>
                  <option value="2015">2015</option>
                  <option value="2016">2016</option>
                  <option value="2017">2017</option>
            </select>
            
			
            </div><!-- search_option_1 -->
        </div><!-- end of search_option -->
        <input type="submit" value="Submit" />
        </form>
        <table cellpadding="0" cellspacing="0">
        	<tr class="table_header_1"  valign="top" width="300px;">
            	<!--<a href="#"><div class="left_table_arrow"></div></a>
                <a href="#"><div class="right_table_arrow"></div></a>-->
            	<td colspan="5"><p><?php echo $searchingDate."-".$searchingMonth."-".$searchingYear." To ".$searchingDate1."-".$searchingMonth1."-".$searchingYear1; ?></p></td>
            </tr>
            <tr valign="top" class="table_header_2">
            	<td width="60px"><p>Date</p></td>
                <td width="60px;"><p>Day</p></td>
                <td width="60px;"><p>In Time</p></td>
                <td width="60px;"><p>Out Time</p></td>
                <td width="60px;"><p>Status</p></td>
            </tr>
            <?php 
				$collectSearchingDataFromDb = "SELECT * FROM attendance WHERE e_id = '$eid' and date between '$searchingYear-$searchingMonth-$searchingDate'and '$searchingYear1-$searchingMonth1-$searchingDate1' ";
				$collectSearchingDataFromDbQuery = mysql_query($collectSearchingDataFromDb);
				//echo $sdfds=mysql_num_rows($collectSearchingDataFromDbQuery);
				while($fetchArrayAcordingToTheData = mysql_fetch_array($collectSearchingDataFromDbQuery)){
					$collectDate = $fetchArrayAcordingToTheData['date'];
					$collectDay = $fetchArrayAcordingToTheData['day'];
					$collectInTime = $fetchArrayAcordingToTheData['in_time'];
					$collectOutTime = $fetchArrayAcordingToTheData['out_time'];
					$collectSatus = $fetchArrayAcordingToTheData['status'];
			?>
                <tr valign="top" class="table_header_3">
                    <td width="60px"><p><?php echo $collectDate ?></p></td>
                    <td width="60px;"><p><?php echo $collectDay ?></p></td>
                    <td width="60px;"><p><?php echo date('h:i A',strtotime($collectInTime)); ?></p></td>
                	<td width="60px;"><p><?php echo date('h:i A',strtotime($collectOutTime)); ?></p></td>
                    <td width="60px;">
                    	<?php
                		if($collectSatus==0){
						?>
                			<p style="color:#F00">Late</p>
                		<?php
                		}
						else if($collectSatus==2){
						?>
                        	<p style="color:#C90">Absent</p>
                        <?php
						}
						else{						
						?>
                			<p style="color:#060">In Time</p>                          
               			 <?php
						}
						?>
                    </td>
                </tr>
             <?php
				}
			 ?>
        </table>
    </div><!-- end of page_content -->
</body>
</html>
